package com.ym.medical.service.task;

import cn.hutool.extra.spring.SpringUtil;
import com.alibaba.fastjson.JSONObject;
import com.ym.core.rabbit.AbstractDelayedTask;
import com.ym.core.utils.tkmybatis.TK;
import com.ym.medical.domain.entity.CounsellingRoomEntity;
import com.ym.medical.domain.entity.InquiryOrderEntity;
import com.ym.medical.domain.entity.OrderFlowRecordEntity;
import com.ym.medical.service.ICounsellingRoomSV;
import com.ym.medical.service.IDoctorSV;
import com.ym.medical.service.IInquiryOrderSV;
import com.ym.medical.service.IOrderFlowRecordSV;

/**
 * 华为自动挂断电话任务
 *
 * @author: 李涛
 * @version: 2019年09月19日 15:24
 */
public class HuaWeiShutDownPhoneTask extends AbstractDelayedTask {


	public HuaWeiShutDownPhoneTask(String describe, long delayTime, JSONObject params) {
		super(describe, delayTime, params);
	}

	@Override
	public void run() {
		JSONObject params = this.getParams();
		IDoctorSV iDoctorSV = SpringUtil.getBean(IDoctorSV.class);
		IInquiryOrderSV inquiryOrderSV = SpringUtil.getBean(IInquiryOrderSV.class);
		IOrderFlowRecordSV iOrderFlowRecordSV = SpringUtil.getBean(IOrderFlowRecordSV.class);
		ICounsellingRoomSV iCounsellingRoomSV = SpringUtil.getBean(ICounsellingRoomSV.class);
		//挂断
		iDoctorSV.axbStopCall(params.getString("sessionId"));
		LOG.info("====================>华为应答事件 + 挂机触发");
		//更改订单状态
		inquiryOrderSV.updateById((InquiryOrderEntity)params.get("model2"));
		//更改流转表状态
		iOrderFlowRecordSV.updateByParams((OrderFlowRecordEntity) params.get("orderFlowRecord"),(TK<OrderFlowRecordEntity>) params.get("model4")) ;
		//更改聊天室状态已经完成
		iCounsellingRoomSV.updateByParams((CounsellingRoomEntity)params.get("room"),(TK<CounsellingRoomEntity>)params.get("model3"));
		LOG.info("====================>华为应答事件 + 更改聊天室状态");
	}
}
